package workers;

import java.util.concurrent.BlockingQueue;

import model.Software;
import workerUIs.StepFrame;
import workflow.step.ArchitectureDesignStep;

/**
 * ArchitectureStepWorker class.
 * 
 * @author Mark Czotter
 * @author Miklos Szennai
 * 
 */
public class ArchitectureStepWorker extends AbstractStepSwingWorker {

	protected final BlockingQueue<Software> inputQueue;
	protected final BlockingQueue<Software> outputImplQueue;
	protected final BlockingQueue<Software> outputUIQueue;
	protected final StepFrame nextFrameImpl;
	private final StepFrame nextFrameUI;
	
	public ArchitectureStepWorker(final StepFrame frame, final BlockingQueue<Software> inputQueue, final BlockingQueue<Software> outputImpl, final BlockingQueue<Software> outputUI, final StepFrame nextFrameImpl, final StepFrame nextFrameUI) {
		super(frame);
		this.inputQueue = inputQueue;
		this.outputImplQueue = outputImpl;
		this.outputUIQueue = outputUI;
		this.nextFrameImpl = nextFrameImpl;
		this.nextFrameUI = nextFrameUI;
	}

	@Override
	protected Software doInBackground() throws Exception {
		Software software = this.inputQueue.take();
		this.software = software;
		new ArchitectureDesignStep().doStep(software);
		this.outputImplQueue.put(software);
		this.outputUIQueue.put(software);
		return this.software;
	}
	
	@Override
	protected void done() {
		super.done();
		if (inputQueue.isEmpty()) {
			getFrame().getNextButton().setEnabled(false);
		}
		this.nextFrameImpl.getNextButton().setEnabled(true);
		this.nextFrameUI.getNextButton().setEnabled(true);
	}

}
